FROM php:8.2-fpm

RUN apt-get update -y
RUN apt-get upgrade -y

RUN apt-get install -y \
  curl \
  git \
  unzip \
  zip

RUN apt-get install -y \
  libonig-dev \
  libpng-dev \
  libpq-dev \
  libxml2-dev \
  libzip-dev \
  zlib1g-dev

RUN docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql

RUN docker-php-ext-install \
  bcmath \
  gd \
  pdo \
  pdo_pgsql \
  pgsql \
  zip

COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

# RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
#   apt-get install -y nodejs

COPY --from=node:latest /usr/local/lib/node_modules /usr/local/lib/node_modules
COPY --from=node:latest /usr/local/bin/node /usr/local/bin/node
RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm

RUN set -e ; \
  pecl install xdebug-3.2.0; \
  docker-php-ext-enable xdebug;

COPY ./xdebug.ini /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini
COPY ./error_reporting.ini /usr/local/etc/php/conf.d/error_reporting.ini

ARG PUID=1000
ENV PUID ${PUID}
ARG PGID=1000
ENV PGID ${PGID}

RUN groupadd -g ${PGID} valerio && \
    useradd -l -u ${PUID} -g valerio -m valerio && \
    usermod -p "*" valerio -s /bin/bash

RUN echo fs.inotify.max_user_watches= 131070 | tee -a /etc/sysctl.conf

USER valerio
